package samples;

public class SampleService
{
	// All public methods could be called via SOAP.
	// You don't need special preparation for this in this class!
	// See sample.xml for details.
	
	public String sampleMethod(String mystring, int count)
	{
		String result = "";
		
		for(int i=0; i<count; i++) {
			result += mystring;
		}
		
		return result;
	}
	
	
	public int mult(int a, int b)
	{
		return a * b;
	}
	
	public void premult(de.fmui.spheon.jsoap.SoapContext context)
	{
		System.out.println("before call 'mult'");
		System.out.println("SOAPAction: " + context.getInputEnvelope().getSoapAction());
		System.out.println("Input envelope:" + context.getInputEnvelope());	
	}
		
	public void postmult(de.fmui.spheon.jsoap.SoapContext context)
	{
		System.out.println("after call 'mult'");
		System.out.println("Output envelope:" + context.getOutputEnvelope());	
	}


	public double div(int a, int b)
		throws de.fmui.spheon.jsoap.SoapFaultException
	{
		if(b == 0) {
			throw new de.fmui.spheon.jsoap.SoapFaultException("Division by 0!");		
		}
		
		return a / b;
	}
	
	public int sum(de.fmui.spheon.jsoap.SoapArray intArray)
		throws de.fmui.spheon.jsoap.SoapFaultException
	{
		if(intArray.isNull()) { return 0; }
		if(intArray.getType() != int.class) {
			throw new de.fmui.spheon.jsoap.SoapFaultException("Expected an array of integer!");
		}


		int result = 0;
		
		for(int i = intArray.getLower()[0]; i <= intArray.getUpper()[0]; i++) {
			
			if(intArray.exists(i)) {
				result += intArray.getInt(i);
			}
		}
				
		return result;
	}
		
	
	public SampleStruct getSampleStruct(SampleStruct struct)
	{
		return struct;
	}
	
	
	public String giveMeANumberBetween1And10(int n)
		throws de.fmui.spheon.jsoap.SoapFaultException
	{
		if((n>0) && (n<11)) { return "Thank you!"; }
		
		throw new de.fmui.spheon.jsoap.SoapFaultException(n + " is not between 1 and 10!");
	}
	
	
	public de.fmui.spheon.jsoap.transport.Attachment attached(de.fmui.spheon.jsoap.transport.Attachment attachement)
	{
		return attachement;
	}
}